<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="700px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="150px">
          <el-form-item label="活动" prop="activityId">
            <el-input
              v-if="false"
              v-model="form.activityId"
              style="width: 370px;"
            />
            <div v-if="form.activityId">
              {{ dialogTableDataActivityId.showInputValue ? dialogTableDataActivityId.showInputValue : form.activityTitle}}
            </div>
            <!-- 新增组件弹出式表单 -->
            <dialogTable
              :dialogTableData.sync="dialogTableDataActivityId"
              @select-callback="dialogTableSelectedCallBackActivityId"
            ></dialogTable>
          </el-form-item>
          <el-form-item label="商家信息及套餐" prop="sponsorBenefitId">
            <el-input
              v-if="false"
              v-model="form.sponsorBenefitId"
              style="width: 370px;"
            />
            <div v-if="form.sponsorBenefitId">
              {{ dialogTableDataSponsorBenefitId.showInputValue ? dialogTableDataSponsorBenefitId.showInputValue : form.sponsorName +'-'+from.benefitName}}
            </div>
            <!-- 新增组件弹出式表单 -->
            <dialogTable
              :dialogTableData.sync="dialogTableDataSponsorBenefitId"
              @select-callback="dialogTableSelectedCallBackSponsorBenefitId"
            ></dialogTable>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column v-if="columns.visible('activityTitle')" prop="activityTitle" label="活动标题" />
        <el-table-column v-if="columns.visible('activityCode')" prop="activityCode" label="活动编码" />
        <el-table-column v-if="columns.visible('activityStatus')" prop="activityStatus" label="活动状态">
          <template slot-scope="scope">
            {{ dict.label.ACTIVITY_STATUS[scope.row.activityStatus] }}
          </template>
        </el-table-column>
        <el-table-column v-if="columns.visible('sponsorName')" prop="sponsorName" label="商家" />
        <el-table-column v-if="columns.visible('sponsorTypeMeaning')" prop="sponsorTypeMeaning" label="商家类型" />
        <el-table-column v-if="columns.visible('sponsorTeamName')" prop="sponsorTeamName" label="姓名" />
        <el-table-column v-if="columns.visible('benefitName')" prop="benefitName" label="套餐名称" />
        <el-table-column v-permission="['admin','tanzerActivitySponsorCorrelation:edit','tanzerActivitySponsorCorrelation:del']" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudTanzerActivitySponsorCorrelation from '@/api/tanzer/tanzerActivitySponsorCorrelation'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation.vue'
import crudOperation from '@crud/CRUD.operation.vue'
import udOperation from '@crud/UD.operation.vue'
import pagination from '@crud/Pagination.vue'
import MaterialList from "@/components/material/index.vue";
import dialogTable from "@/views/components/dialogTable/index.vue";

// crud交由presenter持有
const defaultCrud = CRUD({ title: '活动商家关联', url: 'api/tanzerActivitySponsorCorrelation', sort: 'id,desc', crudMethod: { ...crudTanzerActivitySponsorCorrelation }})
const defaultForm = { id: null, sponsorBenefitId: null, activityId: null, isDel: null, createTime: null, createBy: null, updateBy: null, updateTime: null }
export default {
  name: 'TanzerActivitySponsorCorrelation',
  components: {dialogTable, pagination, crudOperation, rrOperation, udOperation ,MaterialList},
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
  dicts: ['SPONSOR_BENEFIT_STATUS','ACTIVITY_STATUS'],
  data() {
    return {

      permission: {
        add: ['admin', 'tanzerActivitySponsorCorrelation:add'],
        edit: ['admin', 'tanzerActivitySponsorCorrelation:edit'],
        del: ['admin', 'tanzerActivitySponsorCorrelation:del']
      },
      rules: {
        sponsorBenefitId: [
          { required: true, message: '商家套餐id不能为空', trigger: 'blur' }
        ],
        activityId: [
          { required: true, message: '活动id不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'sponsorName', display_name: '商家' },
        { key: 'activityCode', display_name: '活动编码' },
        { key: 'activityTitle', display_name: '活动' },
      ],

      dialogTableDataSponsorBenefitId: {
        title: "商家信息及套餐",
        dialogVisible: false,
        url: "api/tanzerSponsorBenefit",
        sort: "id,desc",
        buttonContext: "选择商家及套餐",
        showInputValue: "",
        queryTypeOptions: [
          { key: 'sponsorName', display_name: '名称' },
          { key: 'sponsorCode', display_name: '编码' },
          { key: 'benefitName', display_name: '套餐' },
        ],
        elTtableColumns: [
          {
            columnProp: "sponsorName",
            columnLabel: "名称"
          },
          {
            columnProp: "sponsorCode",
            columnLabel: "编码"
          },
          {
            columnProp: "benefitName",
            columnLabel: "套餐"
          },
        ]
      },
      dialogTableDataActivityId: {
        title: "活动",
        dialogVisible: false,
        url: "api/tanzerActivity",
        sort: "id,desc",
        buttonContext: "选择活动",
        showInputValue: "",
        queryTypeOptions: [
          { key: 'activityTitle', display_name: '名称' },
          { key: 'activityCode', display_name: '编码' },
        ],
        elTtableColumns: [
          {
            columnProp: "activityTitle",
            columnLabel: "名称"
          },
          {
            columnProp: "activityCode",
            columnLabel: "编码"
          },
          {
            columnProp: "activityStatus",
            columnLabel: "状态"
          },
        ]
      },
    }
  },
  watch: {
  },
  methods: {
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },


    dialogTableSelectedCallBackActivityId(row) {
      this.form.activityId = row.id;
      if (this.form.activityId) {
        this.dialogTableDataActivityId.showInputValue = row.activityTitle;
      }
    },

    dialogTableSelectedCallBackSponsorBenefitId(row) {
      this.form.sponsorBenefitId = row.id;
      if (this.form.sponsorBenefitId) {
        this.dialogTableDataSponsorBenefitId.showInputValue = row.sponsorName +'-'+row.benefitName;
      }
    },
  }
}



</script>

<style scoped>
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
</style>
